<%--
    Document   : ViewForum
    Created on : Apr 21, 2011, 5:47:30 AM
    Author     : Ruba
--%>

<%@page import="xmlMapping.Post"%>
<%@page import="java.util.Set"%>
<%@page import="java.lang.Integer"%>
<%@page import="java.util.TreeSet"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib  prefix="ds" uri="/WEB-INF/tlds/displaycategories.tld" %>
<%@taglib prefix="dss" uri="/WEB-INF/tlds/displayPoststag.tld" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@taglib  prefix="t" uri="http://java.sun.com/jstl/core_rt" %>
<%@taglib  prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>

<script type="text/javascript" >
    <!--
    var answer;
    var postid;
    function dialog(postid)
    {
        answer = confirm("Are you sure you want to delete this post?")
        if (answer){

            alert(postid);
            //alert(document.getElementById('postid').value);

            // document.write(postid);
            document.location = 'http://localhost:8084/jetsForum/deletePost.do?threadid=${param.threadid}&postid=${postid}'

        }

    }
    //-->
</script>
<%--  this script for ajax call for ranking post    --%>
  <script type="text/javascript">
         var xmlhttp = new getXMLObject();	//xmlhttp holds the ajax object   
    function getXMLObject()  //XML OBJECT
{
   var xmlHttp = false;
   try {
     xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
   }
   catch (e) {
     try {
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
     }
     catch (e2) {
       xmlHttp = false   // No Browser accepts the XMLHTTP Object then false
     }
   }
   if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
     xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
   }
   return xmlHttp;  // Mandatory Statement returning the ajax object created
} 

 
function rankpost(rank,post) {
  if(xmlhttp) { 
     
  	
        
        
        
       
    xmlhttp.open("POST","rank.do",true); //getname will be the servlet name
    
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlhttp.onreadystatechange  = handleServerResponse;
    xmlhttp.send("rank="+rank+"&postid="+post); //Posting txtname to Servlet
    
   
    
   
   
  }
}
 
function handleServerResponse() {
   if (xmlhttp.readyState == 4) {
      
     if(xmlhttp.status == 200) {
alert("Your Data has Changed  ");  
     }
     else {
        alert("Erorr You may rank this befor ");
     }
   }
}
          
          
          
          
          
          
          
          
  </script>

<div id="page-body">

    <h2><bean:write name="thread" property="title"/></h2>
    <!-- NOTE: remove the style="display: none" when you want to have the forum description on the topic body --><div style="display: none !important;">Description of your first forum.<br /></div>

    <div class="topic-actions">

        <div class="buttons">

            <div class="reply-icon"><a href="checkLogin.do?threadid=${param.threadid}&act=addPost" title="Post a reply"><span></span>Post a reply</a></div>
            <div class="split-thread-icon"><a href="#" title="Split"><span></span></a></div>
            <div class="delete-thread-icon"><a href="#" title="Delete"><span></span></a></div>
            <div class="rename-thread-icon"><a href="#" title="Rename"><span></span></a></div>
            <div class="stick-thread-icon"><a href="#" title="Stick"><span></span></a></div>
            <div class="move-thread-icon"><a href="#" title="Move"><span></span></a></div>
            <div class="block-thread-icon"><a href="#" title="Block"><span></span></a></div>
            <div class="lock-thread-icon"><html:link page="/admguest2.do?actiontype=lockthread&id=${param.threadid}" title="Lock"><span></span></html:link></div>

        </div>


        <div class="search-box">
            <form method="post" id="topic-search" action="./search.php?t=4">
                <fieldset>
                    <input class="inputbox search tiny"  type="text" name="keywords" id="search_keywords" size="20" value="Search this topic…" onclick="if(this.value=='Search this topic…')this.value='';" onblur="if(this.value=='')this.value='Search this topic…';" />
                    <input class="button2" type="submit" value="Search" />
                    <input type="hidden" value="4" name="t" />
                    <input type="hidden" value="msgonly" name="sf" />
                </fieldset>
            </form>
        </div>

        <div class="pagination">
			1 post
            &bull; Page <strong>1</strong> of <strong>1</strong>
        </div>


    </div>
    <div class="clear"></div>

    <bean:define name="thread" property="member" id="member"/>


    <logic:notEqual name="question" value="">
        <div id="p6" class="codebox bg1"  >
            <div class="inner">
                <span class="corners-top"><span></span></span>
                <div class="postbody">	<h3 class="first">
                        Vote: <bean:write name="question"/></h3>
                    <div class="content"><table width="500">
                            <html:form action="vote.do?threadid=${param.threadid}">
                            <logic:iterate name="answers" id="answer">
                                <logic:notEqual name="vote" value="true">
                                       <tr><td width="80%"><html:radio name="VoteNow" property="choice" value="${answer.id}"/>
                                                <bean:write name="answer" property="choice"/>
                                                </td><td width="20%">
                                                <bean:write name="answer" property="percent"/> %</td></tr>
                                        </logic:notEqual>
                                        <logic:equal name="vote" value="true">
                                    <tr><td width="80%"><bean:write name="answer" property="choice"/></td><td width="20%">
                                            <bean:write name="answer" property="percent"/> %</td></tr>
                                        </logic:equal>
                                    </logic:iterate>
                                    <logic:notEqual name="vote" value="true">
                                        <tr><td><h3><html:submit value="Vote"/></h3></td></tr>
                                    </logic:notEqual>
                                    </html:form>
                            </table>
                            <logic:equal name="vote" value="true">
                            <font color="red" size="1">*You must be signed in to Vote and you can only vote Once.</font>
                        </logic:equal>
                    </div></div>
                <div class="back2top">
                    <a href="#wrap" class="top" title="Top">Top</a></div>
                <span class="corners-bottom"><span></span></span></div></div>

    </logic:notEqual>

    <div class="clear"></div>
    <hr class="divider" />
    <div id="p6" class="codebox bg1"  >
        <div class="inner">
            <span class="corners-top"><span></span></span>
            <div class="postbody">	<h3 class="first"><bean:write name="thread" property="title"/></h3>
                <p class="author">
                    <html:link page="viewtopic.html">
                        <img src="imageset/icon_post_target.gif" width="11" height="9" alt="Post" title="Post" />
                    </html:link>by <strong>
                        <html:link page="./memberlist.php?mode=viewprofile&amp;u=2\" style=\"color: #AA0000;\" class=\"username-coloured">
                            <bean:write name="member" property="userName"/>
                        </html:link></strong>
                    &raquo; <bean:write name="thread" property="lastModified"/> </p>
                <div class="content">
                    <bean:write name="thread" property="body" filter="false"/>
                </div>
                <div id="sig6" class="signature">This is just a test signature.</div></div>
            <dl class="postprofile" id="profile6"><dt>

                    <html:link page="memberlist.html">
                        <img src="" width="80" height="80" alt="User avatar" />
                    </html:link><br />

                    <html:link page="memberlist.html">
                        <bean:write name="member" property="userName"/>
                    </html:link></dt>


                <dd>Site Admin</dd><dd>&nbsp;</dd><dd><strong></strong> </dd><dd>
                    <strong></strong> </dd></dl>    
                    <logic:notEmpty name="type" scope="session">
                        <logic:notEqual name="type" scope="session" value="mem">
                            <logic:equal name="type" scope="session" value="mod">
                                <logic:iterate name="forums"  id="forum">
                                    <logic:equal name="forum" property="forumId" value="${thread.forum.forumId}">
                                        <logic:notEqual name="member" property="userName" value="${sessionScope.username}">
                                            <logic:equal name="permessions" property="deletethread" value="true">
                                                <html:link action="/threadMod.do?actionType=delete&forumId=${param.forumId}" paramName="thread" paramProperty="threadId" paramId="threadId">Delete</html:link></logic:equal> <br>
                                    <logic:equal name="permessions" property="editthread" value="true">
                                        <html:link page="/editThread.do" paramName="thread" paramProperty="threadId" paramId="threadId">Edit</html:link>
                                    </logic:equal></logic:notEqual>
                            </logic:equal>
                        </logic:iterate>
                    </logic:equal>


                    <logic:notEqual name="type" scope="session" value="mod">
                        <logic:notEqual name="member" property="userName" value="${sessionScope.username}">
                            <html:link action="/threadMod.do?actionType=delete&forumId=${param.forumId}" paramName="thread" paramProperty="threadId" paramId="threadId">Delete</html:link> <br>
                            <html:link page="/editThread.do" paramName="thread" paramProperty="threadId" paramId="threadId">Edit</html:link><br>
                            <logic:equal name="question" value="" scope="request">
                                <html:link page="/newvote.jsp?thread=${param.threadid}">Add Vote</html:link><br>
                            </logic:equal>
                            <logic:notEqual name="question" value="" scope="request">
                                <html:link page="/deletevote.do?threadid=${param.threadid}">Delete Vote</html:link><br>
                            </logic:notEqual>
                        </logic:notEqual></logic:notEqual></logic:notEqual>

                <%--check if loginned --%>
                <c:if test="${sessionScope.username != null}">
                    <%--check if the loginned user is the threadowner if yes display these buttons--%>
                    <logic:equal name="member" property="userName" value="${sessionScope.username}">
                        <html:link action="/threadMod.do?actionType=delete&forumId=${param.forumId}" paramName="thread" paramProperty="threadId" paramId="threadId">Delete</html:link> <br>
                        <html:link page="/editThread.do" paramName="thread" paramProperty="threadId" paramId="threadId">Edit</html:link><br>
                        <logic:equal name="question" value="" scope="request">
                                <html:link page="/newvote.jsp?thread=${param.threadid}">Add Vote</html:link><br>
                            </logic:equal>
                            <logic:notEqual name="question" value="" scope="request">
                                <html:link page="/deletevote.do?threadid=${param.threadid}">Delete Vote</html:link><br>
                            </logic:notEqual>
                    </logic:equal>
                </c:if>

            </logic:notEmpty><div class="back2top">
                <a href="#wrap" class="top" title="Top">Top</a></div>
            <span class="corners-bottom"><span></span></span></div></div>

    <%-- -------------------------------------Posts Display ---------------------------------------%>

    <html:form action="/managepost?pagenumber=${requestScope.pagenumber}&typeOperation=mergePost&thId=${thread.threadId}" method="post">

        <logic:iterate name="thread" property="posts" id="post">
            <bean:define name="post" property="member" id="member"/>
                                                             
    
            <br> <br>  <div id="p6" class="post bg2"  >
                <div class="inner"><span class="corners-top"><span></span></span>
                    <div class="postbody">
                        <h3 class="first">
                            <html:link page="#p6">
                                <bean:write name="post" property="title"/>
                            </html:link></h3>
                        <p class="author">
                            <html:link page="viewtopic.html">
                                <img src="imageset/icon_post_target.gif" width="11" height="9" alt="Post" title="Post" />
                            </html:link>by <strong>
                                <html:link page="./memberlist.php?mode=viewprofile&amp;u=2">
                                    <bean:write name="member" property="userName"/></html:link></strong> &raquo;
                            <bean:write name="post" property="lastModified"/> </p>
                        <div class="content">
                            <bean:write name="post" property="body" filter="false"/>
                            <br></br>
                       
                            <% 
                            if(request.getAttribute("postss")!=null){
                    Set<Integer>  ranked=(Set<Integer>)request.getAttribute("postss");
                    Post posttt=(Post)pageContext.getAttribute("post");
                    
Integer postiiiii=posttt.getPostId();
out.print("post is "+postiiiii);
if(!ranked.contains(postiiiii))
       {

  %>
         <script>	
		
		$(function(){
		$('#${post.postId}').slider({ value: 0 });
		
		
	$( '#${post.postId}' ).slider({
   stop: function(event, ui) { 
rankpost(ui.value,${post.postId});
    $( "#${post.postId}" ).slider({ disabled: true });
}
});
  
                        
			});
			</script> 
                    
                        <div id="${post.postId}" style="width: 80px;left:950px"> </div>
                             <%}
                             else
                    {
    out.print("<h4> ranked </h4> ");
                             }
                            }
                             %>
                            
                        </div>
                        <div id="sig6" class="signature">This is just a test signature.</div></div>
                    <dl class="postprofile" id="profile6">
                        <dt><html:link page="memberlist.html">
                               <img src=" <bean:write name="member" property="photo"/>" width="80" height="80" alt="User avatar" />
                            </html:link><br />
                            <html:link page="memberlist.html">
                                <bean:write name="member" property="userName"/>

                            </html:link><br/>

                        <%
                    Set<Integer>  ranked=(Set<Integer>)request.getAttribute("postss");
                    Post po=(Post)pageContext.getAttribute("post");
Integer postiiiii=po.getPostId();//(Integer)pageContext.getAttribute("postid");

if(!ranked.contains(postiiiii))
       {

  %>
         <script>

		$(function(){
		$('#${post.postId}').slider({ value: 0 });


	$( '#${post.postId}' ).slider({
   stop: function(event, ui) {
rankpost(ui.value,${post.postId});
    $( "#${post.postId}" ).slider({ disabled: true });
}
});


			});
			</script>

                        <div id="${post.postId}" style="width: 80px"> </div>
                             <%}
                             else
                                                                 {
    out.print("<h4> ranked </h4> ");
                             }
                             %>

                        </dt>	<dd></dd><br><br>

                       
                            
                            
                            
                            
                            
                        <logic:notEmpty name="type" scope="session">
                            
                            
                            
                            <logic:notEqual name="type" scope="session" value="mem">
                                <logic:equal name="type" scope="session" value="mod">
                                    <logic:iterate name="forums"  id="forum">
                                        <logic:equal name="forum" property="forumId" value="${thread.forum.forumId}">
                                            <logic:notEqual name="member" property="type" value="adm">
                                            <dd><logic:equal name="permessions" property="suspenduser" value="true">
                                                    <html:link page="#">
                                                        <logic:empty name="member" property="suspendsForMemberId">
                                                            <html:link action="/sususer.do?pagenumber=${requestScope.pagenumber}&mid=${member.memberId}&threadid=${param.threadid}">suspend</html:link></logic:empty>
                                                        <logic:notEmpty name="member" property="suspendsForMemberId">
                                                            <html:link action="/unsuspend.do?pagenumber=${requestScope.pagenumber}&mid=${member.memberId}&threadid=${param.threadid}">unsuspend</html:link></logic:notEmpty>
                                                    </html:link>
                                                </logic:equal> </logic:notEqual><br/>

                                                <logic:notEqual name="member" property="type" value="adm">
                                                <logic:equal name="permessions" property="banuser" value="true">
                                                    
                                                        <logic:empty name="member" property="banByMemberId" >
                                                            <html:link action="/banuser.do?pagenumber=${requestScope.pagenumber}&mid=${member.memberId}&threadid=${param.threadid}">ban</html:link></logic:empty>
                                                        <logic:notEmpty name="member" property="banByMemberId" >
                                                            <html:link action="/unban.do?pagenumber=${requestScope.pagenumber}&mid=${member.memberId}&threadid=${param.threadid}">unban</html:link></logic:notEmpty>
                                                    
                                                </logic:equal></logic:notEqual><br/>

                                                <logic:notEqual name="member" property="type" value="adm">
                                                <html:link page="#">send Msg</html:link><br/>
                                                <html:link page="#">mod</html:link></logic:notEqual></dd>
                                            </logic:equal></logic:iterate>
                                    </logic:equal>

                                <logic:notEqual name="type" scope="session" value="mod">
                                    <dd><logic:notEqual name="member" property="type" value="adm">
                                            <logic:empty name="member" property="suspendsForMemberId">
                                                <html:link action="/sususer.do?pagenumber=${requestScope.pagenumber}&mid=${member.memberId}&threadid=${param.threadid}">suspend</html:link></logic:empty>
                                            <logic:notEmpty name="member" property="suspendsForMemberId">
                                                <html:link action="/unsuspend.do?pagenumber=${requestScope.pagenumber}&mid=${member.memberId}&threadid=${param.threadid}">unsuspend</html:link></logic:notEmpty>
                                        <br/>
                                        
                                            <logic:empty name="member" property="banByMemberId" >
                                                <html:link action="/banuser.do?pagenumber=${requestScope.pagenumber}&mid=${member.memberId}&threadid=${param.threadid}">ban</html:link></logic:empty>
                                            <logic:notEmpty name="member" property="banByMemberId" >
                                                <html:link action="/unban.do?pagenumber=${requestScope.pagenumber}&mid=${member.memberId}&threadid=${param.threadid}">unban</html:link></logic:notEmpty>
                                        <br/>

                                        <html:link page="#">send Msg</html:link><br/>
                                        <html:link page="#">mod</html:link></logic:notEqual></dd>
                                    </logic:notEqual>
                                </logic:notEqual>
                            </logic:notEmpty>

                        <dd>&nbsp;</dd><dd><strong>Posts:</strong> 27</dd><dd><strong>Joined:</strong> Mon Oct 11, 2010 7:55 am</dd>
                    </dl><logic:notEmpty name="type" scope="session">

                        <logic:equal name="type" scope="session" value="mem">

                            <logic:equal  name="member" property="memberId" value="${sessionScope.id}">
                                <bean:define name="post" property="postId" id="postid"/>

                                <a href="deletePost.do?pagenumber=${requestScope.pagenumber}&threadid=${param.threadid}&postid=${pageScope.postid}">Delete</a><br/>
                                <html:link page="/EditPost.jsp?pagenumber=${requestScope.pagenumber}&threadid=${param.threadid}&postid=${pageScope.postid}">Edit</html:link><br>
                                
                                  
                             
                                
                            </logic:equal>
                                
                        </logic:equal>    
                   <logic:notEqual name="type" scope="session" value="mem">
                            <logic:equal name="type" scope="session" value="mod">
                                <logic:iterate name="forums"  id="forum">
                                    <logic:equal name="forum" property="forumId" value="${thread.forum.forumId}">
                                        <logic:equal name="permessions" property="deletepost" value="true">
                                            <bean:define name="post" property="postId" id="postid"/>

                                            <a href="deletePost.do?pagenumber=${requestScope.pagenumber}&threadid=${param.threadid}&postid=${pageScope.postid}">Delete</a><br/>
                                        </logic:equal>
                                        <logic:equal name="permessions" property="editpost" value="true">
                                            <bean:define name="post" property="postId" id="postid"/>
                                            <html:link page="/EditPost.jsp?pagenumber=${requestScope.pagenumber}&threadid=${param.threadid}&postid=${pageScope.postid}">Edit</html:link><br>                                            <html:link page="/managepost.do?pagenumber=${requestScope.pagenumber}&typeOperation=preMovepost&postid=${post.postId}&thId=${thread.threadId}">Move</html:link><br>
                                            <html:link action="/managepost.do?pagenumber=${requestScope.pagenumber}&typeOperation=preSplitpost&postid=${post.postId}&thId=${thread.threadId}">Split</html:link><br>
                                            <font color="red">merge</font><html:multibox property="merge" value="${post.postId}"/>
                                        </logic:equal>
                                    </logic:equal>
                                </logic:iterate>
                            </logic:equal>

                            <logic:notEqual name="type" scope="session" value="mod">
                                <bean:define name="post" property="postId" id="postid"/>
                                <a href="deletePost.do?pagenumber=${requestScope.pagenumber}&threadid=${param.threadid}&postid=${pageScope.postid}">Delete</a><br/>
                                <html:link page="/EditPost.jsp?pagenumber=${requestScope.pagenumber}&threadid=${param.threadid}&postid=${pageScope.postid}">Edit</html:link><br>
                                <br><html:link action="/managepost.do?pagenumber=${requestScope.pagenumber}&typeOperation=preMovepost&postid=${post.postId}&thId=${thread.threadId}">Move</html:link><br>
                                <html:link action="/managepost.do?pagenumber=${requestScope.pagenumber}&typeOperation=preSplitpost&postid=${post.postId}&thId=${thread.threadId}">Split</html:link><br>
                                <font color="red">merge</font><html:multibox property="merge" value="${post.postId}"/>
                            </logic:notEqual>
                        </logic:notEqual>


                    </logic:notEmpty><div class="back2top"><a href="#wrap" class="top" title="Top">Top</a></div>
                    <span class="corners-bottom"><span></span></span></div></div>	<hr class="divider" />

        </logic:iterate><logic:notEmpty name="type" scope="session"><logic:notEqual name="type" scope="session" value="mem"><font size="3">title of 2 post :</font><html:text property="title"/> <html:submit>merge</html:submit></logic:notEqual></logic:notEmpty>

    </html:form>
    <div class="pagination">
			1 post
        &bull; Page <strong>1</strong> of <strong>1</strong>
    </div>

</div>


    <p></p><p><a href="viewforum.html" class="left-box left" accesskey="r">Return to Your first forum</a></p>
    <logic:greaterThan value="1" name="numpage" scope="request">
        <p><h3>  &nbsp; &nbsp;  Pages:    &nbsp; &nbsp;
            <c:forEach begin="1" end="${ requestScope.numpage}" var="current">
                &nbsp;
                <logic:equal  value="${requestScope.pagenumber}" name="${current}">
                    <font color="red" size="3">${requestScope.pagenumber}</font>
                </logic:equal>
                <logic:notEqual value="${requestScope.pagenumber}" name="${current}">
                    <html:link action="/thread.do?pagenumber=${current}&threadid=${thread.threadId}" >${current}</html:link>
                </logic:notEqual>
                 
            </c:forEach>
          
        </logic:greaterThan> </h3></p>

<form method="post" id="jumpbox" action="./viewforum.php" onsubmit="if(document.jumpbox.f.value == -1){return false;}">


    <fieldset class="jumpbox">

        <label for="f" accesskey="j">Jump to:</label>
        <select name="f" id="f" onchange="if(this.options[this.selectedIndex].value != -1){ document.forms['jumpbox'].submit() }">

            <option value="-1">Select a forum</option>
            <option value="-1">------------------</option>
            <option value="1">Your first category</option>

            <option value="2" selected="selected">&nbsp; &nbsp;Your first forum</option>

            <option value="3">&nbsp; &nbsp;Another Forum</option>

            <option value="4">Another category</option>

            <option value="5">&nbsp; &nbsp;Yet another forum</option>

        </select>
        <input type="submit" value="Go" class="button2" />
    </fieldset>



</form>



